/*
 * Lightning.h
 *
 *  Created on: 2011-04-04
 *      Author: lpieczkowski
 */

#ifndef LIGHTNING_H_
#define LIGHTNING_H_

class Lightning
{
public:
	Lightning(float curDetail)
	{
		this->curDetail = curDetail;
	}
	~Lightning()
	{

	}

	void drawLightning(float x1, float y1, float x2, float y2, float displace)
	{
		glLoadIdentity();

		if (displace < curDetail)
		{
			GLfloat verts[8];

			GLfloat v,w;
			v = x2 - x1;
			w = y2 - y1;

			v *= 0.1;
			w *= 0.1;

			verts[0] = x1 + w;
			verts[1] = y1 - v;
			verts[2] = x1 - w;
			verts[3] = y1 + v;

			verts[4] = x2 + w;
			verts[5] = y2 - v;
			verts[6] = x2 - w;
			verts[7] = y2 + v;

			//AppLog("(%f,%f) | (%f,%f)\n", x1, y1, x2, y2);

			glVertexPointer(2, GL_FLOAT, 0, verts);
			glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		}
		else
		{
			float mid_x = (x2+x1)/2;
			float mid_y = (y2+y1)/2;
			mid_x += ((float)(Math::Rand()%11 / 100.0f) - 0.05f) * displace * 0.06f;
			mid_y += ((float)(Math::Rand()%11 / 100.0f) - 0.05f) * displace * 0.06f;
			drawLightning(x1,y1,mid_x,mid_y,displace/2);
			drawLightning(x2,y2,mid_x,mid_y,displace/2);
		}
	}

private:

	float curDetail;

};

#endif /* LIGHTNING_H_ */
